#if !defined(_APP_DEVICE)
#define _APP_DEVICE
#include "app_message.h"
#include "app_buffer.h"
#include <pthread.h>


//设备类型
typedef enum{
    DEV_GENERAL,
    DEV_SERIAL,
    DEV_USB,
}DeviceType;

//设备相关函数
typedef struct{
    //读取设备数据的后置函数
    int (*post_read)(Device *device,char *data,int len);
    //写入设备数据的前置函数
    int (*post_write)(Device *device,char *data,int len);
    int (*send_msg)(Device *device,char *data,int len);
}DeviceFuns;

//设备结构体
typedef struct{
    char *filname;//文件名
    int fd;//文件描述符
    ConnectionTYPES conn_type;
    DeviceType dev_type;
    Buffer *read_buffer;
    Buffer *write_buffer;
    pthread_t read_thread;
    int running;
    DeviceFuns *funs;//设备相关函数
}Device;

//初始化设备
Device *app_device_init(char*filname);
//启动设备
int app_device_start(Device *dev);
//停止设备
int app_device_stop(Device *dev);
//关闭释放设备
int app_device_close(Device *dev);


#endif // _APP_DEVICE
